import { Entity, PrimaryGeneratedColumn } from "typeorm";
import { Code, CreateDate, DateTime, Desc, Digdit, Jsonb, Name, Text, Title, UpdateDate } from "../utils";
/**
 * 任务管理
 */
@Entity({
    name: `auto_task`
})
export class AutoTask {
    @PrimaryGeneratedColumn()
    id: number;

    @Title()
    title: string;

    @Name({
        unique: true
    })
    name: string;

    @Desc({ default: `` })
    desc: string;

    @CreateDate()
    create_date: Date;

    @Text({ nullable: true })
    code: string;
}

@Entity({
    name: 'auto_task_script_log'
})
export class AutoTaskScriptLog {
    @PrimaryGeneratedColumn()
    id: number;

    @Name()
    script_name: string;

    @Code()
    device_uuid: string;

    @Code()
    task_name: string;

    @Name()
    package_name: string;

    @Jsonb({ nullable: true })
    result: any;

    @DateTime({ comment: '执行时间' })
    run_time: Date;

    @DateTime({ nullable: true })
    finish_time: Date;

}

@Entity({
    name: 'auto_task_script_notfound'
})
export class AutoTaskScriptNotFound {
    @PrimaryGeneratedColumn()
    id: number;

    @Name()
    package_name: string;

    @Name()
    task_name: string;

    @CreateDate()
    create_date: Date;

    @Desc({ default: '' })
    desc: string;

    @UpdateDate()
    update_date: Date;
}

/**
 * 任务脚本
 */
@Entity({
    name: 'auto_task_script'
})
export class AutoTaskScript {
    @PrimaryGeneratedColumn()
    id: number;

    @Title()
    title: string;

    @Name()
    name: string;

    @Name()
    package_name: string;

    @Name()
    task_name: string;

    @Digdit({ default: 0 })
    display_order: number;

    @CreateDate()
    create_date: Date;

    @Digdit()
    timeout: number;

    @Text()
    code: string;

}